@include("/common/_html_start.html", {title: record.title!}){}
@include("/common/_froala_css.html"){}
<link rel="stylesheet" href="${ctxPath}/css/bootstrap-tagsinput.css">
@include("/common/_header.html"){}


<section class="container">
	<form action="/blog/updateBlog" method="post">
		<input type="hidden" value="${record.id!}" name="id">
		<input type="hidden" value="${record.uid!}" name="uid">
		@include("/blog/blogForm.html"){}

	</form>
</section>


@include("/common/_bottom.html"){}
@include("/common/_footer.html"){}
@include("/common/_html_common_js.html"){}
@include("/common/_froala_js.html"){}
<script type="text/javascript" src="${ctxPath}/js/bootstrap-tagsinput.min.js"></script>
<script>
	$(function() {


		//初始化froala-edit
		new FroalaEditor("textarea#edit", {
			spellcheck: false,
			language: 'zh-cn',
			htmlExecuteScripts:false,
			htmlUntouched: true,
			events: {

				//转base64
				"image.beforeUpload": function (files) {
					const editor = this;
					if (files.length) {
						var reader = new FileReader();
						reader.onload = function (e) {
							var result = e.target.result;
							editor.image.insert(result, null, null, editor.image.get());
						}
						reader.readAsDataURL(files[0]);
					}
					return false;
				}
			}
		});

		//初始化input-tag
		var tagsInputObj = $("#myTags");
		var allTagsInputObj = $("#allTags");
		tagsInputObj.tagsinput({
			allowDuplicates: false,
			itemValue: "value",
			itemText: "text"
		});
		allTagsInputObj.tagsinput({
			allowDuplicates: false,
			itemValue: "value",
			itemText: "text"
		});

		var tagMap = new Map();
		@for(tag in tagList!){
			tagMap.set("${tag.id}","${tag.tag}");
			allTagsInputObj.tagsinput("add", {"value": "${tag.id}", "text": "${tag.tag}"});
		@}

		for(var tagId of "${record.tags!}".split(",")) {
			tagId = $.trim(tagId);
			for(var key of tagMap.keys()){
				if(tagId == key) {
					tagsInputObj.tagsinput("add", {"value": tagId, "text": tagMap.get(key)});
				}
			}
		}

		allTagsInputObj.on('beforeItemRemove', function(event) {
			tagsInputObj.tagsinput("add", {"value": event.item.value, "text": event.item.text});
		});

		tagsInputObj.on('beforeItemRemove', function(event) {
			allTagsInputObj.tagsinput("add", {"value": event.item.value, "text": event.item.text});
		});

	})
</script>
@include("/common/_html_end.html"){}